﻿var initialLocation; //申明地图中心地址变量
//var tianjin = new BMap.LatLng(39, 117);
var browserSupportFlag = false; //申明浏览器是否支持检测地理位置标识变量，默认不支持

var browser = new Browser();
// Determine browser and version
var mapPointCollection;
var allPointCollection = [];
var zoomDefault = 12;
var zoomShowMarketLabel = 13;
var tilesloaded = 0;
var infowindowContent = "";
var terminalinfo = "";
var infowindow;
var infowindow_state = 0;
var mgrloaded = 0;
var setCenter_t = 0;
var Realtimetrajectory;
var allRealtimetrajectory = [];
var map;
var mgr;
var icons = {};
var allmarkers = [];
var allmarkersText = [];
var allmarkersTitle = [];
var allmarkers1 = [];
var allmarkersText1 = [];

var allmarkersZZZ = [];
var allmarkersCLC = [];
var allmarkersCY = [];
var allmarkersXQCY = [];
var allmarkersNCD = [];
var allmarkersXQQT = [];

var allmarkersZZZLabel = [];
var allmarkersCLCLabel = [];
var allmarkersCYLabel = [];
var allmarkersXQCYLabel = [];
var allmarkersNCDLabel = [];
var allmarkersXQQTLabel = [];

var isShowZZZLabel;
var isShowCLCLabel;
var isShowCYLabel;
var isShowXQCYLabel;
var isShowNCDLabel;
var isShowXQQTLabel;

var marketSelect;
var marketALARM;
var path;
var startyoun = 0; //是否做好准备
var selmarker;
var geocoder;
var address;
var iconData = {
    "blank": { width: 20, height: 34 },
    "marke": { width: 20, height: 34 },
    "shadow50": { width: 28, height: 22 },
    "shadow51": { width: 37, height: 34 },
    "us": { width: 24, height: 14 },
    "ca": { width: 24, height: 14 },
    "flag-shadow": { width: 40, height: 30 },
    "house": { width: 32, height: 32 },
    "house-shadow": { width: 59, height: 32 },
    "headquarters": { width: 32, height: 32 },
    "headquarters-shadow": { width: 59, height: 32 }
};
var menuarray = new Array(2);
menuarray[0] = "<a href='#' onClick='window.parent.theCarVideo();'>视频监控</a>&nbsp;<a href='#' onClick='window.parent.returnPosition();'>立即回传</a>&nbsp;<a href='#'  onClick='window.parent.returnSetting();'>回传设置</a>&nbsp;<a href='#'  onClick='window.parent.speedSetting();'>速度限制</a>&nbsp;<a href='#'  onClick='window.parent.historyPlay();'>轨迹回放</a>&nbsp;<a href='#'  onClick='nextmenu();' style='text-decoration:none'>&gt;</a>";
menuarray[1] = "<a href='#' onClick='Previousmenu();' style='text-decoration:none'>&lt;</a>&nbsp;<a href='#'  onClick='window.parent.setupElectronicfence();'>设置围栏</a>&nbsp;<a href='#'  onClick='window.parent.cancelRectangle();'>取消围栏</a>";

function Browser() {
    var ua, s, i;

    this.isIE = false;
    this.isNS = false;
    this.isOP = false;
    this.name = navigator.appName;
    this.version = null;

    ua = navigator.userAgent;
    if ((navigator.userAgent).indexOf("Opera") != -1) {
        this.isOP = true;
    } else
        if (navigator.appName == "Netscape") {
            this.isNS = true;
            //s = "Netscape6/";
            //this.version = parseFloat(ua.substr(i + s.length));
        } else
            if ((navigator.appName).indexOf("Microsoft") != -1) {
                this.isIE = true;
                //s = "MSIE";
                //this.version = parseFloat(ua.substr(i + s.length));
            }

    return;
}

var menuindex = 0;
function Previousmenu() {
    if (menuindex > 0) {
        menuindex = menuindex - 1;
        document.getElementById("meuncontl").innerHTML = menuarray[menuindex];
    }
}
function nextmenu() {
    if (menuindex < menuarray.length - 1) {
        menuindex = menuindex + 1;
        document.getElementById("meuncontl").innerHTML = menuarray[menuindex];
    }
}
function getmenu() {
    if (document.getElementById("meuncontl") != null) {
        document.getElementById("meuncontl").innerHTML = menuarray[menuindex];
    }
}
function creatediv() {
    if (document.getElementById("infowindowcontent") == null) {
        document.getElementById("infowdiv").innerHTML = "<div id='infowindowcontent'><span class='infowindowSTYLE' >处理中！</span></div>"
    }
}
function createline(jdx, wdy) {
    //    path = Realtimetrajectory.getPath();
    //    path.push(new BMap.Point(jdx, wdy));
    allRealtimetrajectory.push(new BMap.Point(jdx, wdy));

}
function drawline() {
    //    var path = Realtimetrajectory.getPath();
    Realtimetrajectory = new BMap.Polyline(allRealtimetrajectory, {
        strokeColor: "#FF0000",
        strokeOpacity: 1.0,
        strokeWeight: 2
    })
    map.addOverlay(Realtimetrajectory);
    //allRealtimetrajectory.push(Realtimetrajectory1);
}
function removeline() {
    map.removeOverlay(Realtimetrajectory);
    allRealtimetrajectory = [];
}
function setterminalinfo(instr) {
    terminalinfo = instr;
}
function delayRun(code, time) {//延时执行函数
    var t = setTimeout(code, time);
}

function initTULI(currentService) {
    //---------------------------
    // 定义一个控件类,即function
    function ZoomControl() {
        // 默认停靠位置和偏移量
        this.defaultAnchor = BMAP_ANCHOR_TOP_RIGHT;
        this.defaultOffset = new BMap.Size(10, 10);
    }

    // 通过JavaScript的prototype属性继承于BMap.Control
    ZoomControl.prototype = new BMap.Control();

    // 自定义控件必须实现自己的initialize方法,并且将控件的DOM元素返回
    // 在本方法中创建个div元素作为控件的容器,并将其添加到地图容器中
    ZoomControl.prototype.initialize = function (map) {
        // 创建一个DOM元素
        var div = document.createElement("img");
        var imgSRC = "../images/TULI" + currentService + ".png";
        div.src = imgSRC;
        // 添加DOM元素到地图中
        map.getContainer().appendChild(div);
        // 将DOM元素返回
        return div;
    }
    // 创建控件
    var myZoomCtrl = new ZoomControl();
    // 添加到地图当中
    map.addControl(myZoomCtrl);

}

function initialize() {
    // 百度地图API功能
    map = new BMap.Map("map_canvas", { enableMapClick: false }); // 创建Map实例 构造底图时，关闭底图可点功能 
    map.centerAndZoom("天津", zoomDefault);      // 初始化地图,用城市名设置地图中心点 houruixian 12
    map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
    map.setCurrentCity("天津");          // 设置地图显示的城市 此项是必须设置的
    //控制控件的位置,anchor:表示停靠在地图的哪个脚，offset指定偏移量，离地图边界相隔多少像素  
    //BMAP_ANCHOR_TOP_LEFT详见百度API说明  
    var opts = { anchor: BMAP_ANCHOR_TOP_LEFT, offset: new BMap.Size(10, 10) }; //houruixian (10,10)
    map.addControl(new BMap.NavigationControl(opts));  //缩放控件  
    map.addControl(new BMap.ScaleControl());   //比例尺控件  
    map.addControl(new BMap.OverviewMapControl());  //小地图
    //    map.addControl(new BMap.MapTypeControl({ mapTypes: [BMAP_NORMAL_MAP, BMAP_HYBRID_MAP] })); //地图类型（地图、卫星、三维）


    //---------------------------
    //监听事件，监听地图放大缩小 2019 zx
    map.addEventListener("zoomend", function () {
        resetCarMarkets();
    });

    var padding = 200;
    var mgr = new BMapLib.MarkerManager(map, {
        borderPadding: padding
		, maxZoom: 18
		, trackMarkers: true
    });
    browserSupportFlag = false;
    infowindow = new BMap.InfoWindow({
        content: document.getElementById("infowindowcontent")
    });
    Realtimetrajectory = new BMap.Polyline({
        strokeColor: "#FF0000",
        strokeOpacity: 1.0,
        strokeWeight: 2
    });
    geocoder = new BMap.Geocoder();

    startyoun = 1;
    window.parent.startmap();
}

function setinfowindow_state(state) {
    infowindow_state = state;
}

function getAddress(jdx, wdy, openy, isAlarm) {
    infowindow.close();
    infowindow = "";
    if (infowindow_state == 1) {
        if (map.getZoom() > zoomDefault && !isAlarm) {
            infowindow = new BMap.InfoWindow({
                content: document.getElementById("infowindowcontent")
            }, { offset: new BMap.Size(0, -20) });
        } else {
            infowindow = new BMap.InfoWindow({
                content: document.getElementById("infowindowcontent")
            });
        }

        infowindow.addEventListener('closeclick', function () {
            infowindow_state = 0;
        });
        creatediv();
        document.getElementById("infowindowcontent").innerHTML = "<span class='infowindowSTYLE'>" + terminalinfo + "</span>";
        getmenu();
        infowindowContent = terminalinfo;
        infowindowContent = infowindowContent.replace(/地址：解析中<br>&nbsp;/g, "");
        var latlng = new BMap.Point(jdx, wdy);
        infowindow.setPosition(latlng);


        //
        infowindow.addEventListener("close", function () {
            if (marketALARM) {
                marketALARM.enableMassClear();
                map.removeOverlay(marketALARM);
            }
            if (marketSelect) {
                marketSelect.enableMassClear();
                map.removeOverlay(marketSelect);
            }
        });
        if (latlng != null) {
            address = latlng;
            geocoder.getLocation(latlng, function (results) {
                creatediv();
                if (results) {
                    //var strarray=new Array();
                    strarray = results.address; //(results[0].formatted_address).toString().split(" ");
                    //var adressstr="地址："+strarray[0];
                    var adressstr = "地址：" + strarray;
                    document.getElementById("infowindowcontent").innerHTML = "<span class='infowindowSTYLE' >" + infowindowContent + adressstr + "</span>";
                    infowindow.setContent(document.getElementById("infowindowcontent"));
                    //infowindow.setPosition(latlng);
                    //infowindow.open(map,selmarker);
                } else {
                    //alert("No results found");
                    document.getElementById("infowindowcontent").innerHTML = "<span class='infowindowSTYLE' >" + infowindowContent + "地址：解析失败" + "</span>";
                    infowindow.setContent(document.getElementById("infowindowcontent"));
                }
                getmenu();
                if (openy == 1) {
                    infowindow.close();
                    //	                    infowindow.open(map, selmarker);
                    map.openInfoWindow(infowindow, new BMap.Point(jdx, wdy))

                    document.getElementById("infowindowcontent").innerHTML = infowindowContent;

                }
            });
        }
    }
}


function closeInfoWindow() {
    infowindow.close();
    infowindow_state = 0;
}
function openInfoWindow() {
    //	    infowindow.open(map, selmarker);
    map.openInfoWindow(infowindow, new BMap.Point(selmarker.getPosition().lng, selmarker.getPosition().lat))

    infowindow_state = 1;
}
function getstartyoun() {
    return startyoun;
}
function setCenter(jdx, wdy) { //定位函数
    if (setCenter_t == 0) {
        //        map.setZoom(14);
        map.setCenter(new BMap.Point(jdx, wdy));
        setCenter_t = 1;
    } else {
        map.setCenter(new BMap.Point(jdx, wdy));
    }
}

function setCenter1() { //回到初始的状态
    map.setCenter(new BMap.LatLng(39, 117));
}

function createfontmarker(jdx, wdy, markertext) {//创建marker,带文字,固定样式
    var officeLayer = [
	  {
	      "zoom": [0, 19],
	      "places": [
		  {
		      "name": markertext,
		      //"icon": ["marke", "shadow50"],
		      "icon": ["blank", "shadow50"],
		      "posn": [jdx, wdy]
		  }
		]
	  }
	];

    var layer = officeLayer[0];
    var place = layer["places"][0];
    var icon = getIcon(place["icon"]);
    var title = place["name"];
    var posn = new BMap.Point(place["posn"][0], place["posn"][1]);
    //var marker = createMarker(posn, title, icon);
    var marker = createMarker(posn, title, '../images/marke/marke.png');
    map.addOverlay(marker);
    //    allmarkers.push(marker);

    //    allmarkers[0].addEventListener('click', function() {
    //        getAddress(allmarkers[0].getPosition().lng, allmarkers[0].getPosition().lat);
    //        map.openInfoWindow(infowindow, allmarkers[0])
    //        infowindow_state = 1;
    //    });

}
function createMarkerALARM(jdx, wdy, title, icon) {
    if (marketALARM) {
        marketALARM.enableMassClear();
        map.removeOverlay(marketALARM);
    }
    var iconName = "../images/alarm.png";
    var myIcon = new BMap.Icon(iconName, new BMap.Size(28, 28));
    marketALARM = new BMap.Marker(new BMap.Point(jdx, wdy), { icon: myIcon }); // 创建点
    marketALARM.disableMassClear();
    map.addOverlay(marketALARM);
}
function curMapZoom() {
    return map.getZoom();
}
function resetCarMarkets() {
    //
    if (map.getZoom() > zoomDefault) {
        map.clearOverlays();
        for (i = 0; i < allmarkers.length; i++) {
            var reMarket = allmarkers[i];


            if (map.getZoom() > zoomShowMarketLabel) {
                var title = allmarkersTitle[i];
                var label = new window.BMap.Label(title, { offset: new window.BMap.Size(20, -10) });
                reMarket.setLabel(label);
            }

            map.addOverlay(reMarket);
        }

    } else {
        map.clearOverlays();
        //map.addOverlay(mapPointCollection);  // 添加海量点
        createfontmarkerExPoint(allPointCollection);
    }

    //垃圾收集点 添加名称label
    if (map.getZoom() > zoomShowMarketLabel) {

        for (i = 0; i < allmarkersZZZ.length; i++) {
            allmarkersZZZ[i].getLabel().setStyle({ display: 'block' });
            isShowZZZLabel = true;
        }
        for (i = 0; i < allmarkersCLC.length; i++) {
            allmarkersCLC[i].getLabel().setStyle({ display: 'block' });
            isShowCLCLabel = true;
        }
        for (i = 0; i < allmarkersCY.length; i++) {
            allmarkersCY[i].getLabel().setStyle({ display: 'block' });
            isShowCYLabel = true;
        }
        for (i = 0; i < allmarkersXQCY.length; i++) {
            allmarkersXQCY[i].getLabel().setStyle({ display: 'block' });
            isShowXQCYLabel = true;
        }
        for (i = 0; i < allmarkersNCD.length; i++) {
            allmarkersNCD[i].getLabel().setStyle({ display: 'block' });
            isShowNCDLabel = true;
        }
        for (i = 0; i < allmarkersXQQT.length; i++) {
            allmarkersXQQT[i].getLabel().setStyle({ display: 'block' });

            isShowXQQTLabel = true;
        }
    } else {
        if (isShowZZZLabel) {
            for (i = 0; i < allmarkersZZZ.length; i++) {
                allmarkersZZZ[i].getLabel().setStyle({ display: 'none' });
            }
            isShowZZZLabel = false;
        }
        if (isShowCLCLabel) {
            for (i = 0; i < allmarkersCLC.length; i++) {
                allmarkersCLC[i].getLabel().setStyle({ display: 'none' });
            }
            isShowCLCLabel = false;
        }
        if (isShowCYLabel) {
            for (i = 0; i < allmarkersCY.length; i++) {
                allmarkersCY[i].getLabel().setStyle({ display: 'none' });
            }
            isShowCYLabel = false;
        }
        if (isShowXQCYLabel) {
            for (i = 0; i < allmarkersXQCY.length; i++) {
                allmarkersXQCY[i].getLabel().setStyle({ display: 'none' });
            }
            isShowXQCYLabel = false;
        }
        if (isShowNCDLabel) {
            for (i = 0; i < allmarkersNCD.length; i++) {
                allmarkersNCD[i].getLabel().setStyle({ display: 'none' });
            }
            isShowNCDLabel = false;
        }
        if (isShowXQQTLabel) {
            for (i = 0; i < allmarkersXQQT.length; i++) {
                allmarkersXQQT[i].getLabel().setStyle({ display: 'none' });
            }
            isShowXQQTLabel = false;
        }
    }
}

//2020.02.13
function createfontmarkerEx(jdx, wdy, title, iconName, overText) {//创建marker,带文字,固定样式
    var posn = new BMap.Point(jdx, wdy);
    var icon = new BMap.Icon("../images/marke/" + iconName, new BMap.Size(32, 70), {    //小车图片
        imageOffset: new BMap.Size(0, 0)    //图片的偏移量。为了是图片底部中心对准坐标点。
    });
    var marker = new BMap.Marker(posn, { icon: icon });
    marker.setTitle(title);
    marker.setRotation(1);
    allmarkers.push(marker);
    allmarkersTitle.push(title);

    if (map.getZoom() > zoomShowMarketLabel) {
        marker.setLabel(new window.BMap.Label(title, { offset: new window.BMap.Size(20, -10) }));
    }
    if (map.getZoom() > zoomDefault) {
        map.addOverlay(marker);
    }

    marker.addEventListener('click', function (e) {
        // 通过点击的坐标创建一个点对象，添加标签
        //        var point = new BMap.Point(e.point.lng, e.point.lat);
        var opts = {
            title: this.getTitle(),
            enableMessage: false,
            offset: new BMap.Size(0, -25)
        };
        var infowindow = new BMap.InfoWindow(
        //        "<div style=\"font-size:12px;\">经 纬 度 详 情" + "<br/>" + e.point.lng + "， " + e.point.lat + "</div>" +
                '<INPUT style="margin-top:10px;" onclick=theCarVideo(' + this.getPosition().lng + ',' + this.getPosition().lat + ') type=button value=监控视频 name=Button1>', opts);
        map.openInfoWindow(infowindow, this.getPosition());
    });
}

function removeMarkerPlaceCLC() {
    for (i = 0; i < allmarkersCLC.length; i++) {
        allmarkersCLC[i].enableMassClear();
        map.removeOverlay(allmarkersCLC[i]);
    }
    allmarkersCLC = [];
    allmarkersCLCLabel = [];
}

function createMarkerPlaceCLC(jdx, wdy, type, name, m2) {//创建marker,带文字,固定样式
    if (allmarkersCLC.length) {
        removeMarkerPlaceCLC();
    }
    var iconName = "../images/PLACE/" + type + ".bmp";
    var myIcon = new BMap.Icon(iconName, new BMap.Size(28, 28));
    var marker = new BMap.Marker(new BMap.Point(jdx, wdy), { icon: myIcon }); // 创建点
    marker.disableMassClear();
    allmarkersCLC.push(marker);
    map.addOverlay(marker);
//    allmarkersCLCLabel.push(name);
    marker.setLabel(new window.BMap.Label(name, { offset: new window.BMap.Size(20, -10) }));
    if (map.getZoom() > zoomShowMarketLabel) {
        marker.getLabel().setStyle({ display: 'block' });
        isShowCLCLabel = true;
    } else {
        marker.getLabel().setStyle({ display: 'none' });
        isShowCLCLabel = false;
    }
}
function removeMarkerPlaceZZZ() {
    for (i = 0; i < allmarkersZZZ.length; i++) {
        allmarkersZZZ[i].enableMassClear();
        map.removeOverlay(allmarkersZZZ[i]);
    }
    allmarkersZZZ = [];
    allmarkersZZZLabel = [];
}
function createMarkerPlaceZZZ(jdx, wdy, type, name, m2) {//创建marker,带文字,固定样式
//    if (allmarkersZZZ.length) {
//        removeMarkerPlaceZZZ();
//    } 
        var iconName = "../images/PLACE/" + type + ".bmp";
        var myIcon = new BMap.Icon(iconName, new BMap.Size(28, 28));
        var marker = new BMap.Marker(new BMap.Point(jdx, wdy), { icon: myIcon }); // 创建点
        marker.disableMassClear();
        allmarkersZZZ.push(marker);
        map.addOverlay(marker);
        marker.setLabel(new window.BMap.Label(name, { offset: new window.BMap.Size(20, -10) }));
        if (map.getZoom() > zoomShowMarketLabel) {
            marker.getLabel().setStyle({ display: 'block' });
            isShowZZZLabel = true;
        } else {
            marker.getLabel().setStyle({ display: 'none' });
            isShowZZZLabel = false;
        }

}
function removeMarkerPlaceNCD() {
//    if (allmarkersNCD.length) {
        for (i = 0; i < allmarkersNCD.length; i++) {
            allmarkersNCD[i].enableMassClear();
            map.removeOverlay(allmarkersNCD[i]);
        }
        allmarkersNCD = [];
        allmarkersNCDLabel = [];
//    }
}
function createMarkerPlaceNCD(jdx, wdy, type, name, m2) {//创建marker,带文字,固定样式
//    removeMarkerPlaceNCD();

    var iconName = "../images/PLACE/" + type + ".bmp";
    var myIcon = new BMap.Icon(iconName, new BMap.Size(28, 28));
    var marker = new BMap.Marker(new BMap.Point(jdx, wdy), { icon: myIcon }); // 创建点
    marker.disableMassClear();
    allmarkersNCD.push(marker);
    map.addOverlay(marker);
    marker.setLabel(new window.BMap.Label(name, { offset: new window.BMap.Size(20, -10) }));
    if (map.getZoom() > zoomShowMarketLabel) {
        marker.getLabel().setStyle({ display: 'block' });
        isShowNCDLabel = true;
    } else {
        marker.getLabel().setStyle({ display: 'none' });
        isShowNCDLabel = false;
    }
}
function removeMarkerPlaceCY() {
    for (i = 0; i < allmarkersCY.length; i++) {
        allmarkersCY[i].enableMassClear();
        map.removeOverlay(allmarkersCY[i]);
    }
    allmarkersCY = [];
    allmarkersCYLabel = [];
}
function createMarkerPlaceCY(jdx, wdy, type, name, m2) {//创建marker,带文字,固定样式
    var iconName = "../images/PLACE/" + type + ".bmp";
    var myIcon = new BMap.Icon(iconName, new BMap.Size(28, 28));
    var marker = new BMap.Marker(new BMap.Point(jdx, wdy), { icon: myIcon }); // 创建点
    marker.disableMassClear();
    allmarkersCY.push(marker);
    map.addOverlay(marker);
    marker.setLabel(new window.BMap.Label(name, { offset: new window.BMap.Size(20, -10) }));
    if (map.getZoom() > zoomShowMarketLabel) {
        marker.getLabel().setStyle({ display: 'block' });
        isShowCYLabel = true;
    } else {
        marker.getLabel().setStyle({ display: 'none' });
        isShowCYLabel = false;
    }
}
function removeMarkerPlaceXQQT() {
    for (i = 0; i < allmarkersXQQT.length; i++) {
        allmarkersXQQT[i].enableMassClear();
        map.removeOverlay(allmarkersXQQT[i]);
    }
    allmarkersXQQT = [];
    allmarkersXQQTLabel = [];
}
function createMarkerPlaceXQQT(jdx, wdy, type, name, m2) {//创建marker,带文字,固定样式

    var iconName = "../images/PLACE/" + type + ".bmp";
    var myIcon = new BMap.Icon(iconName, new BMap.Size(28, 28));
    var marker = new BMap.Marker(new BMap.Point(jdx, wdy), { icon: myIcon }); // 创建点
    marker.disableMassClear();
    allmarkersXQQT.push(marker);
    map.addOverlay(marker);
    marker.setLabel(new window.BMap.Label(name, { offset: new window.BMap.Size(20, -10) }));
    if (map.getZoom() > zoomShowMarketLabel) {
        marker.getLabel().setStyle({ display: 'block' });
        isShowXQQTLabel = true;
    } else {
        marker.getLabel().setStyle({ display: 'none' });
        isShowXQQTLabel = false;
    }
}
function removeMarkerPlaceXQCY() {
    for (i = 0; i < allmarkersXQCY.length; i++) {
        allmarkersXQCY[i].enableMassClear();
        map.removeOverlay(allmarkersXQCY[i]);
    }
    allmarkersXQCY = [];
    allmarkersXQCYLabel = [];
}
function createMarkerPlaceXQCY(jdx, wdy, type, name, m2) {//创建marker,带文字,固定样式
//    removeMarkerPlaceXQCY();
    var iconName = "../images/PLACE/" + type + ".bmp";
    var myIcon = new BMap.Icon(iconName, new BMap.Size(28, 28));
    var marker = new BMap.Marker(new BMap.Point(jdx, wdy), { icon: myIcon }); // 创建点
    marker.disableMassClear();
    allmarkersXQCY.push(marker);
    map.addOverlay(marker);
    marker.setLabel(new window.BMap.Label(name, { offset: new window.BMap.Size(20, -10) }));
    if (map.getZoom() > zoomShowMarketLabel) {
        marker.getLabel().setStyle({ display: 'block' });
        isShowXQCYLabel = true;
    } else {
        marker.getLabel().setStyle({ display: 'none' });
        isShowXQCYLabel = false;
    }
}

function setAllPoint(arrayPoint) {
    allPointCollection = arrayPoint;
    map.clearOverlays();
    createfontmarkerExPoint(allPointCollection);
}

function createfontmarkerExPoint(arrayPoint) {//画海量点

    if (document.createElement('canvas').getContext) {  // 判断当前浏览器是否支持绘制海量点
        var points = [];  // 添加海量点数据
        for (var i = 0; i < arrayPoint.length; i++) {
            var record = arrayPoint[i];
            var lng = record.get('Lng');
            var lat = record.get('Lat');
            points.push(new BMap.Point(lng, lat));
        }
        var options = {
            size: BMAP_POINT_SIZE_SMALL,
            shape: BMAP_POINT_SHAPE_CIRCLE,
            color: '#3F88FC'
        }
        var pointCollection = new BMap.PointCollection(points, options);  // 初始化PointCollection


        pointCollection.addEventListener('click', function (e) {
            //alert(e.get('LicensePlate'));  // 监听点击事件
            //            var overText = "<B><font color='#ff6600'>" + licensePlate + "</font></B><BR><div id='meuncontl' style='text-decoration:none'></div>卡号:" + cardNo + "<BR>" + "状态:" + getStatusName(status) + "<BR>" + "速度:" + speed + "公里/小时<BR>" + "方向:" + getDirectionName(direction) + "<br>" + "时间:" + gpsTime + "<BR>" + "经度:" + lng + "<BR>纬度:" + lat;


            // 通过点击的坐标创建一个点对象，添加标签
            var point = new BMap.Point(e.point.lng, e.point.lat);
            var opts = {
                title: "车辆信息：",
                enableMessage: false
            };
            var infowindow = new BMap.InfoWindow("<div style=\"font-size:12px;\">经 纬 度 详 情" + "<br/>" + e.point.lng + "， " + e.point.lat + "</div>" +
                '<INPUT style="margin-top:10px;" onclick=theCarVideo(' + e.point.lng + ',' + e.point.lat + ') type=button value=监控视频 name=Button1>', opts);
            map.openInfoWindow(infowindow, point);
        });
        //pointCollection.addEventListener('rightclick', function (e) {
        //    //右键点击

        //});
        //pointCollection.addEventListener('click', function (e) {
        //    //alert(e.get('LicensePlate'));  // 监听点击事件
        //    //            var overText = "<B><font color='#ff6600'>" + licensePlate + "</font></B><BR><div id='meuncontl' style='text-decoration:none'></div>卡号:" + cardNo + "<BR>" + "状态:" + getStatusName(status) + "<BR>" + "速度:" + speed + "公里/小时<BR>" + "方向:" + getDirectionName(direction) + "<br>" + "时间:" + gpsTime + "<BR>" + "经度:" + lng + "<BR>纬度:" + lat;


        //    // 通过点击的坐标创建一个点对象，添加标签
        //    var point = new BMap.Point(e.point.lng, e.point.lat);
        //    //        var opts = {
        //    //            title: "经纬度详情：",
        //    //            enableMessage: false,
        //    //        };
        //    var infowindow = new BMap.InfoWindow("经 纬 度 详 情" + "<br/>lng：" + e.point.lng + "<br/>lat" + e.point.lat);
        //    map.openInfoWindow(infowindow, point);
        //});
        //allPointCollection = pointCollection;
        mapPointCollection = pointCollection;

        if (map.getZoom() <= zoomDefault) {
            map.addOverlay(pointCollection);  // 添加Overlay
        }
    } else {
        //        alert('请发大地图查看车辆，或在chrome、safari、IE8+以上浏览器查看');
    }
}

function theCarVideo(lng, lat) {//https://www.oschina.net/code/snippet_260395_39205#60569 百度坐标需要转为GPS坐标
    var videoInfo = Ext.data.Record.create([{ name: 'ICCID'}]);
    // 数据源
    var videoInfo = new Ext.data.Store({
        url: "./Json/JsonGetVehicleCurrentInfoList.ashx",
        autoSync: false,
        reader: new Ext.data.JsonReader({ root: 'data' }, videoInfo)
    });

    videoInfo.load({
        params: { lng: lng, lat: lat, op: 'GetVideoByLoaction' }, //2019.09.20 zx
        autoLoad: true,
        callback: function (records, options, success) {
            if (records.length > 0) {
                var window = new Ext.Window({
                    title: "实时监控视频",
                    layout: 'fit',       //弹出窗口内布局会充满整个窗口;
                    width: 680,          //设置窗口大小;
                    height: 540,
                    //items: tabPanel         //默认会生成Ext.Panel类型的对象;并且随窗口大小改变而改变;
                    items: [
                        {
                            html: '<iframe src="http://111.160.78.62:88/808gps/open/player/video.html?lang=zh&account=admin&password=admin&devIdno=' + records[0].get("ICCID") + '" width="100%" height="100%"></iframe>'
                            //html: '<iframe src="./html/TheCarVideo.html?lang=zh&devIdno=' + '015620509715' + '" width="100%" height="100%"></iframe>'
                            //html: '<iframe src="./html/TheCarVideoByNP.html?lang=zh&account=admin&password=admin&devIdno=' + '015620509715' + '" width="100%" height="100%"></iframe>'
                        }
                    ]
                });
                window.show();
            } else {
                alert("此车暂不提供视频服务");
            }
        }
    });
}

function createselmarker(jdx, wdy) {

    if (selmarker) {
    } else {
        var officeLayer = [
              {
                  "zoom": [0, 19],
                  "places": [
                  {
                      "name": "",
                      "icon": ["marke", "shadow51"],
                      "posn": [wdy, jdx]
                  }
                  ]
              }
        ];


        var layer = officeLayer[0];
        var place = layer["places"][0];
        var icon = getIcon(place["icon"]);
        var title = place["name"];
        var posn = new BMap.LatLng(place["posn"][0], place["posn"][1]);
        selmarker = createMarker1(posn, title, icon);
        //selmarker.draggable();禁止拖动，好像没有相应的方法
        //map.addOverlay(selmarker);
        selmarker.addEventListener('click', function () {
            infowindow_state = 1;
            getAddress(selmarker.getPosition().lng(), selmarker.getPosition().lat(), 0, false);
            map.openInfoWindow(infowindow, new BMap.Point(selmarker.getPosition().lng, selmarker.getPosition().lat))
        });

        selmarker.setMap(map);
    }
}
function selmarker_show() {
    if (selmarker) {
        selmarker.setVisible(true);
    }
}
function selmarker_hide() {
    if (selmarker) {
        selmarker.setVisible(false);
    }
}
function createMarker1(posn, title, icon) {
    var markerOptions = {
        position: posn,
        flat: false,
        title: title
    };
    if (icon !== false) {
        markerOptions.shadow = icon.shadow;
        markerOptions.icon = icon.icon;
        markerOptions.shape = icon.shape;
    }
    var marker = new BMap.Marker(markerOptions);
    marker.setZIndex(900);
    return marker
}
function getIcon(images) {
    var icon = false;
    if (images) {
        if (icons[images[0]]) {
            icon = icons[images[0]];
        } else {
            //			var iconImage = new BMap.MarkerImage('images/marke/' + images[0] + '.png',
            //			new BMap.Size(iconData[images[0]].width, iconData[images[0]].height),
            //			new BMap.Point(0,0),
            //			new BMap.Point(iconData[images[0]].width / 2, iconData[images[0]].height));

            var posn = new BMap.Point(iconData[images[0]].width / 2, iconData[images[0]].height);
            var icon = new BMap.Icon('images/marke/' + images[0] + '.png', new BMap.Size(iconData[images[0]].width, iconData[images[0]].height));
            var iconImage = new BMap.Marker(posn, { icon: icon });

            //			var iconShadow = new BMap.MarkerImage('images/marke/' + images[1] + '.png',
            //			new BMap.Size(iconData[images[1]].width, iconData[images[1]].height),
            //			new BMap.Point(0,0),
            //			new BMap.Point(0, iconData[images[1]].height));
            var posn = new BMap.Point(0, iconData[images[1]].height);
            var icon = new BMap.Icon('images/marke/' + images[0] + '.png', new BMap.Size(iconData[images[1]].width, iconData[images[1]].height));
            var iconShadow = new BMap.Marker(posn, { icon: icon });

            var iconShape = {
                coord: [1, 1, 1, 32, 32, 32, 32, 1],
                type: 'poly'
            };
            icons[images[0]] = {
                icon: iconImage,
                shadow: iconShadow,
                shape: iconShape
            };
            icon = icons[images[0]];
        }
    }
    return icon;
}
//function getIcon(images) {
//    var icon = false;
//    if (images) {
//        if (icons[images[0]]) {
//            icon = icons[images[0]];
//        } else {
//            var iconImage = new BMap.MarkerImage('../images/marke/' + images[0] + '.png',
//			new BMap.Size(iconData[images[0]].width, iconData[images[0]].height),
//			new BMap.Point(0, 0),
//			new BMap.Point(iconData[images[0]].width / 2, iconData[images[0]].height));

//            var iconShadow = new BMap.MarkerImage('../images/marke/' + images[1] + '.png',
//			new BMap.Size(iconData[images[1]].width, iconData[images[1]].height),
//			new BMap.Point(0, 0),
//			new BMap.Point(0, iconData[images[1]].height));
//            var iconShape = {
//                coord: [1, 1, 1, 32, 32, 32, 32, 1],
//                type: 'poly'
//            };
//            icons[images[0]] = {
//                icon: iconImage,
//                shadow: iconShadow,
//                shape: iconShape
//            };
//            icon = icons[images[0]];
//        }
//    }
//    return icon;
//}
function mgrrefresh() {
    //    if (mgrloaded == 1) {
    //	  mgr.addMarkers(allmarkers, 0, 19);
    //	  mgr.refresh();
    //	}
}
function mgrrefreshLys() {
    //    mgr.addMarkers(allmarkers, 0, 19);
    //    alert(allmarkers.length);
    //        mgr.refresh();
}

function setLatLng(jdx, wdy, markeindex) {


    var markerNum = parseInt(markeindex);
    allmarkers[markerNum].setPosition(new BMap.LatLng(wdy, jdx)); //移动标记
    allmarkersText[markerNum].setPosition(new BMap.LatLng(wdy, jdx)); //移动标记

    var bounds = map.getBounds(); //返回地图视口边界 bounds(经/纬坐标)
    var southWest = bounds.getSouthWest(); //西南区
    var northEast = bounds.getNorthEast(); //东北地区
    //longitude and latitude 经度和纬度
    var minX = southWest.lng();
    var maxX = northEast.lng();
    var minY = southWest.lat();
    var maxY = northEast.lat();
    if (jdx < minX + 0.005 || jdx > maxX - 0.005 || wdy < minY + 0.005 || wdy > maxY - 0.005) {
        map.panTo(new BMap.LatLng(wdy, jdx));
    }
}

function setLatLngMonitorEx(jdx, wdy, markeindex, overText) {

    var bounds = map.getBounds(); //返回地图视口边界 bounds(经/纬坐标)
    var southWest = bounds.getSouthWest(); //西南区
    var northEast = bounds.getNorthEast(); //东北地区
    //longitude and latitude 经度和纬度
    var minX = southWest.lng;
    var maxX = northEast.lng;
    var minY = southWest.lat;
    var maxY = northEast.lat;
    if (jdx > minX - 0.005 && jdx < maxX + 0.005 && wdy > minY - 0.005 && wdy < maxY + 0.005) {
        //var markerNum = parseInt(markeindex);
        var markerNum = getMarkerIndex(markeindex);
        allmarkers[markerNum].setPosition(new BMap.Point(jdx, wdy)); //移动标记
        allmarkersText[markerNum].setPosition(new BMap.Point(jdx, wdy)); //移动标记
        allmarkersText[markerNum].setOverText(overText);


        if (jdx < minX + 0.005 || jdx > maxX - 0.005 || wdy < minY + 0.005 || wdy > maxY - 0.005) {
            map.panTo(new BMap.Point(jdx, wdy));
        }
    }

}

function setLatLngEx(jdx, wdy, markeindex, overText) {
    var bounds = map.getBounds(); //返回地图视口边界 bounds(经/纬坐标)
    var southWest = bounds.getSouthWest(); //西南区
    var northEast = bounds.getNorthEast(); //东北地区
    //longitude and latitude 经度和纬度
    var minX = southWest.lng;
    var maxX = northEast.lng;
    var minY = southWest.lat;
    var maxY = northEast.lat;
    if (jdx > minX - 0.005 && jdx < maxX + 0.005 && wdy > minY - 0.005 && wdy < maxY + 0.005) {
        //var markerNum = parseInt(markeindex);
        var markerNum = getMarkerIndex(markeindex);
        allmarkers[markerNum].setPosition(new BMap.Point(jdx, wdy)); //移动标记
        allmarkersText[markerNum].setPosition(new BMap.Point(jdx, wdy)); //移动标记
        allmarkersText[markerNum].setOverText(overText);
    }
}

function resetLatLng(jdx, wdy, markeindex, overText) {
    var bounds = map.getBounds(); //返回地图视口边界 bounds(经/纬坐标)
    var southWest = bounds.getSouthWest(); //西南区
    var northEast = bounds.getNorthEast(); //东北地区
    //longitude and latitude 经度和纬度
    var minX = southWest.lng;
    var maxX = northEast.lng;
    var minY = southWest.lat;
    var maxY = northEast.lat;
//    var markerNum = getMarkerIndex(markeindex);
//    allmarkers[markerNum].setPosition(new BMap.Point(jdx, wdy)); //移动标记
//    allmarkersText[markerNum].setPosition(new BMap.Point(jdx, wdy)); //移动标记
//    allmarkersText[markerNum].setOverText(overText);
    if (marketSelect) {
        marketSelect.enableMassClear();
        map.removeOverlay(marketSelect);
    }
    if (map.getZoom() > zoomDefault) {
        var myIcon = new BMap.Icon("../images/markeS/quan.png", new BMap.Size(42, 42));
        marketSelect = new BMap.Marker(new BMap.Point(jdx, wdy), { icon: myIcon, offset: new BMap.Size(0, -20) }); // 创建点
        marketSelect.disableMassClear();
        map.addOverlay(marketSelect);
    }
}

function setIconName(markeindex, iconName) {
    var markerNum = getMarkerIndex(markeindex);
    //  allmarkers[markerNum].setIcon(new BMap.Icon("../images/marke/" + iconName, new BMap.Size(32, 70)));
}

function setLatLng1(jdx, wdy, markeindex) {
    var markerNum = parseInt(markeindex);
    allmarkers[markerNum].setPosition(new BMap.LatLng(wdy, jdx)); //移动标记
}

function setLatLng2(jdx, wdy) {
    if (selmarker) {
        selmarker.setPosition(new BMap.Point(jdx, wdy)); //移动标记
    } else {
        createselmarker(jdx, wdy)
    }
}
function createMarker(posn, title, icon) {
    var markerOptions = {
        position: posn,
        flat: false,
        title: title
    };
    if (icon !== false) {
        markerOptions.shadow = icon.shadow;
        markerOptions.icon = icon.icon;
        markerOptions.shape = icon.shape;
    }
    var marker = new BMap.Marker(markerOptions);
    return marker
}

function CreateMarkerLys(posn, title, icon) {
    var userMarker = new BMap.Marker({
        position: posn,
        map: map,
        title: title,
        icon: new BMap.MarkerImage(icon)
    });

    //设置标注的图标
    var icon = new BMap.Icon(icon, new BMap.Size(100, 100));
    //设置标注的经纬度
    var marker = new BMap.Marker(new BMap.Point(118.056156, 36.840988), { icon: icon });
    //return new Marker(posn, title, title, 1, image, bsc);
    return userMarker;
}

function getMarkerIndex(cardNo) {

    for (i = 0; i < allmarkers.length; i++) {
        var marker = allmarkers[i];
        if (marker.toString() == "[objectMarker]") {
            if (marker.getLabel().content.split(",")[1] == cardNo)
                return i;
        }
    }
    return -1;
}

function clearOverlays() {//从地图中删除所有标记
    if (allmarkers.length > 0) {
        //        mgr.clearMarkers();
        allmarkers.length = 0;

    }
}

function clearOverlaysLys() {//从地图中删除所有标记
    if (allmarkers.length > 0) {
        //        mgr.clearMarkers();
        allmarkers.length = 0;

    }
}

//清除所有地标对象
this.clearMarkers = function () {
    //    map.clearOverlays()//移除所有遮盖物
    for (i = 0; i < allmarkers.length; i++) {//houruixian
        var marker = allmarkers[i]; //houruixian
        map.removeOverlay(marker);
        //        marker.setMap(null);

        var markerText = allmarkersText[i]; //houruixian
        map.removeOverlay(markerText);

        //        markerText.setMap(null);
    }

    try {

    }
    catch (Exception) { }

    allmarkers = []; //houruixian
    allmarkersText = []; //houruixian
    allmarkersTitle = [];
}

//清除一个地标
this.clearMarker = function (_marker, i) {
    _marker.setMap(null);
    allmarkers.splice(i, 1);

}



